package cn.cjj.gulimall.search.controller;

import cn.cjj.gulimall.search.service.MallSearchService;
import cn.cjj.gulimall.search.vo.SearchParam;
import cn.cjj.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author CuiJunJie
 * @create 2021/6/26-16:46
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;


    @GetMapping("/search.html")
    public String searchPage(SearchParam param, Model model, HttpServletRequest request) {

        param.set_queryString(request.getQueryString());

        SearchResult result = mallSearchService.search(param);

        model.addAttribute("result", result);

        return "search";
    }
}
